package com.jiantong.work.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Strings;
import com.google.common.collect.Maps;
import io.terminus.common.utils.JsonMapper;
import lombok.Data;

import java.io.IOException;
import java.io.Serializable;
import java.util.Map;

/**
 * 督查管理-督查记录
 * Created by mz03 on 2017/3/22.
 * @author :zyp
 */
@Data
public class SupervisionRecords implements Serializable{


    private static final long serialVersionUID = 6477617938273319581L;
    private static final ObjectMapper objectMapper = JsonMapper.nonEmptyMapper().getMapper();


    private Long id;

    /**
     * 编号
     */
    private String number;


    /**
     * 状态，0：待处理，1全部 2待处理 3待确认 4已确认
     */
    private Integer status;

    /**
     *检查人ID
     */
    private Long userId;


    /**
     *检查人名称
     */
    private String userName;



    /**
     *养殖场id
     */
    private Long breedFactoryId;


    /**
     *养殖场名称
     */
    private String breedFactoryName;



    /**
     *养殖类型 1、猪 2、牛 3、羊 4、家禽
     */
    private Integer breedType;


    /**
     *库存（存栏数）
     */
    private Integer stockQuantity;


    /**
     * 畜产品安全检测
     */
    private String safetyDetection;


    /**
     *业主ID
     */
    private Integer ownerId;


    /**
     *业主名
     */
    private String ownerName;



    /**
     *业主电话
     */
    private String ownerMobile;



    /**
     *当前位置
     */
    private String localAddress;



    /**
     *当前位置经度
     */
    private String localLongitude;



    /**
     *当前位置纬度
     */
    private String localLatitude;

    /**
     *动物检查执行情况  animal_check_execution_details
     */
    private String animalCheckExecutionDetails;

    /**
     *病死动物无害化处理情况 harmless_treatment_details
     */
    private String harmlessTreatmentDetails;


    /**
     *投入品使用情况 input_used_details
     */
    private String inputUsedDetails;


    /**
     *污染治理情况 pollution_control_details
     */
    private String pollutionControlDetails;

    /**
     *档案记录情况 record_details
     */
    private String recordDetails;

    /**
     * 整改建议和要求 correct_suggestion
     */
    private String correctSuggestion;

    /**
     * 不存数据库
     */
    private Map<String , Map<String , String>> photoMap;

    /**
     *照片 photo_json
     */
    @JsonIgnore
    private String photoJson;

    /**
     * 视频map
     */
    private Map<String , String> videoMap;

    /**
     *视频 video_json
     */
    @JsonIgnore
    private String videoJson;


    /**
     *视频图片  不存数据库
     */
    private Map<String , Map<String , String>> videoPhotoMap;

    /**
     *视频图片 video_photo_json
     */
    @JsonIgnore
    private String videoPhotoJson;

    /**
     * 删除标志
     */
    private Integer deleteFlag;

    /**
     *created_at
     */
    private String createdAt;

    /**
     *updated_at
     */
    private String updatedAt;

    /*
    private Map<String,String>  videoJsonMap;
    private String videoJson;
     */

    public void setPhotoJson(String photoJson){
        this.photoJson = photoJson;
        if(Strings.isNullOrEmpty(photoJson)){
            this.photoMap = Maps.newHashMap();;
        }else {
            try {
                this.photoMap = objectMapper.readValue(photoJson, new TypeReference<Map<String , Map<String , String>>>(){});
            } catch (IOException e) {
                //ignore this fuck IOException
            }
        }
    }

    public void setPhotoMap(Map<String , Map<String , String>> photoMap){
        this.photoMap = photoMap;
        if(photoMap == null || photoMap.isEmpty()){
            this.photoJson = null;
        }else {
            try {
                this.photoJson = objectMapper.writeValueAsString(photoMap);
            } catch (JsonProcessingException e) {
                //ignore this fuck IOException
            }
        }
    }
    public void setVideoJson(String videoJson){
        this.videoJson = videoJson;

        if(Strings.isNullOrEmpty(videoJson)){
            this.videoMap = Maps.newHashMap();
        }else {
            try {
                this.videoMap = objectMapper.readValue(videoJson, new TypeReference<Map<String , String>>() {});
            } catch (IOException e) {
                //ignore this fuck IOException
            }
        }
    }

    public void setVideoMap(Map<String , String> videoMap){
        this.videoMap = videoMap;

        if(videoMap == null || videoMap.isEmpty()){
            this.videoJson = null;
        }else {
            try {
                this.videoJson = objectMapper.writeValueAsString(videoMap);
            } catch (JsonProcessingException e) {
                //ignore this fuck JsonProcessingException
            }
        }
    }

    public void setVideoPhotoJson(String videoPhotoJson){
        this.videoPhotoJson = videoPhotoJson;

        if(Strings.isNullOrEmpty(videoPhotoJson)){
            this.videoPhotoMap = Maps.newHashMap();
        }else {
            try {
                this.videoPhotoMap = objectMapper.readValue(videoPhotoJson, new TypeReference<Map<String , Map<String , String>>>() {});
            } catch (IOException e) {
                //ignore this fuck IOException
            }
        }
    }

    public void setVideoPhotoMap(Map<String , Map<String , String>> videoPhotoMap){
        this.videoPhotoMap = videoPhotoMap;

        if(videoPhotoMap == null || videoPhotoMap.isEmpty()){
            this.videoPhotoJson = null;
        }else {
            try {
                this.videoPhotoJson= objectMapper.writeValueAsString(videoPhotoMap);
            } catch (JsonProcessingException e) {
                //ignore this fuck JsonProcessingException
            }
        }
    }
}
